//
//  Scheme.swift
//  vr
//
//  Created by 李旭峰 on 2020/7/17.
//

import UIKit

/// 方案
class Scheme {
    /// 方案id
    var schemeId:String = ""
    /// 楼盘名称
    var buildingName:String = ""
    /// 方案主图
    var schemeImage:String = ""
    /// 面积
    var buildingArea:Int = 0
    /// 户型 1室1厅
    var houseParams:HouseParams
    /// 价格
    var price:Int = 0
    /// 方案类型 1：整装 2：软装
    var schemeType:Int?
    /// 方案类型名  整体装修+全屋装修
//    var schemeTypeName:String = ""
    /// 风格名称 欧美风
    var styleName:String = ""
    /// 工期
    var workDays:Int = 0
    /// 预览url
    var schemeUrl:String = ""
    var fillSchemeTypeName:String {
        switch self.schemeType {
        case 1?:return "整体装修+全屋家具"
        case 2?:return "全屋家具"
        default:break
        }
        return ""
    }
    var abbreviationSchemeTypeName:String {
        switch self.schemeType {
        case 1?:return "整装"
        case 2?:return "软装"
        default:break
        }
        return ""
    }
    init(_ json:[String:Any]) {
        schemeId = String.SwitchToString(json["id"]) ?? ""
        buildingName = String.SwitchToString(json["buildingName"]) ?? ""
        schemeImage = String.SwitchToString(json["image"]) ?? ""
        buildingArea = String.SwitchToString(json["buildingArea"])?.decimal.int ?? 0
        if let houseParamsJson = json["houseParams"] as? [String:Any] {
            houseParams = HouseParams(with: houseParamsJson)
        }else {
            houseParams = HouseParams(with: [:])
        }
        price = String.SwitchToString(json["price"])?.decimal.int ?? 0
        schemeType = String.SwitchToString(json["type"])?.decimal.int ?? 0
        styleName = String.SwitchToString(json["style"]) ?? ""
    }
}

class TrtcScheme {
    var authorId:String = ""
    var authorMobile:String = ""
    var authorName:String = ""
    /// 设计师头像
    var authorPic:String = ""
    /// 建筑面积(平方厘米)
    var buildingArea:Int = 0
    /// 楼盘名称
    var buildingName:String = ""
    /// 收藏数量
    var collectionNum:Int = 0
    ///
    var houseParams:HouseParams?
    var id:String = ""
    var image:String = ""
    var isCancel:Bool = false
    var layoutPic:String = ""
    var panoUrl:String = ""
    var position:Int = 0
    var positionName:String = ""
    var price:Int = 0
    var schemeName:String = ""
    var style:String = ""
    var type:Int = 0
    var url:String = ""
    var vrType:Int?
    
    init(with json:[String:Any]) {
        authorId = String.SwitchToString(json["authorId"]) ?? ""
        authorMobile = String.SwitchToString(json["authorMobile"]) ?? ""
        authorName = String.SwitchToString(json["authorName"]) ?? ""
        authorPic = String.SwitchToString(json["authorPic"]) ?? ""
        buildingArea = String.SwitchToString(json["buildingArea"])?.decimal.int ?? 0
        buildingName = String.SwitchToString(json["buildingName"]) ?? ""
        collectionNum = String.SwitchToString(json["collectionNum"])?.decimal.int ?? 0
        if let houseParamsJson = json["houseParams"] as? [String:Any] {
            houseParams = HouseParams(with: houseParamsJson)
        }else {
            houseParams = HouseParams(with: [:])
        }
        id = String.SwitchToString(json["id"]) ?? ""
        image = String.SwitchToString(json["image"]) ?? ""
        isCancel = String.SwitchToString(json["isCancel"])?.decimal.boolValue ?? false
        layoutPic = String.SwitchToString(json["layoutPic"]) ?? ""
        panoUrl = String.SwitchToString(json["panoUrl"]) ?? ""
        panoUrl = String.SwitchToString(json["panoUrl"]) ?? ""
        position = String.SwitchToString(json["position"])?.decimal.int ?? 0
        positionName = String.SwitchToString(json["positionName"]) ?? ""
        price = String.SwitchToString(json["price"])?.decimal.int ?? 0
        schemeName = String.SwitchToString(json["schemeName"]) ?? ""
        style = String.SwitchToString(json["style"]) ?? ""
        type = String.SwitchToString(json["type"])?.decimal.int ?? 0
        url = String.SwitchToString(json["url"]) ?? ""
        vrType = String.SwitchToString(json["vrType"])?.decimal.int ?? 0
    }
}

class HouseParams {
    enum PropertyType {
        /// 阳台数
        case kBalconyNum
        /// 卫生间数
        case kBathroomNum
        /// 卧室数
        case kBedroomNum
        /// 厨房数
        case kKitchenNum
        /// 客厅数
        case kLivingRoomNum
    }
    /// 阳台数
    var balconyNum:Int?
    /// 卫生间数
    var bathroomNum:Int?
    /// 卧室数
    var bedroomNum:Int?
    /// 厨房数
    var kitchenNum:Int?
    /// 客厅数
    var livingRoomNum:Int?
    
    init(with json:[String:Any]) {
        balconyNum = String.SwitchToString("balconyNum")?.decimal.int
        bathroomNum = String.SwitchToString("bathroomNum")?.decimal.int
        bedroomNum = String.SwitchToString("bedroomNum")?.decimal.int
        kitchenNum = String.SwitchToString("kitchenNum")?.decimal.int
        livingRoomNum = String.SwitchToString("livingRoomNum")?.decimal.int
    }
    func houseParams(_ types:[PropertyType]) -> String {
        var str = ""
        if types.contains(.kBedroomNum) && (self.bedroomNum ?? 0) > 0 {
            str = str + "\(self.bedroomNum!)室"
        }
        if types.contains(.kLivingRoomNum) && (self.livingRoomNum ?? 0) > 0 {
            str = str + "\(self.livingRoomNum!)厅"
        }
        if types.contains(.kKitchenNum) && (self.kitchenNum ?? 0) > 0 {
            str = str + "\(self.kitchenNum!)厨"
        }
        if types.contains(.kBalconyNum) && (self.bathroomNum ?? 0) > 0 {
            str = str + "\(self.bathroomNum!)卫"
        }
        if types.contains(.kBalconyNum) && (self.balconyNum ?? 0) > 0 {
            str = str + "\(self.balconyNum!)阳台"
        }
        return str
    }
}
